#include "WString_test.h"

// #include "WString.h"
#include <stdio.h>
// #include <stdlib.h>
#include "stdlib_noniso.h"

void WString_test() {
    // String str_demo = "hello world! 你好";
    // printf("%s\r\n", str_demo.c_str());


    // int num;
    // char str[10];

    // // 测试十进制转十进制
    // num = 123;
    // itoa(num, str, 10);
    // printf("整数 %d 转换为字符串 %s\n", num, str);

    // // 测试十进制转二进制
    // num = 123;
    // itoa(num, str, 2);
    // printf("整数 %d 转换为二进制字符串 %s\n", num, str);

    // // 测试十进制转八进制
    // num = 123;
    // itoa(num, str, 8);
    // printf("整数 %d 转换为八进制字符串 %s\n", num, str);

    // // 测试十进制转十六进制
    // num = 123;
    // itoa(num, str, 16);
    // printf("整数 %d 转换为十六进制字符串 %s\n", num, str);

    // // 测试负数
    // num = -123;
    // itoa(num, str, 10);
    // printf("整数 %d 转换为字符串 %s\n", num, str);

    char buffer[33];
    // Test cases
    printf("itoa(123, buffer, 10) = %s\n", itoa(123, buffer, 10));       // Expected: "123"
    printf("itoa(-123, buffer, 10) = %s\n", itoa(-123, buffer, 10));     // Expected: "-123"
    printf("itoa(255, buffer, 16) = %s\n", itoa(255, buffer, 16));       // Expected: "ff"
    printf("itoa(-255, buffer, 16) = %s\n", itoa(-255, buffer, 16));     // Expected: "ff" (negative not handled in other bases)
    printf("itoa(100, buffer, 2) = %s\n", itoa(100, buffer, 2));         // Expected: "1100100"
    printf("itoa(-100, buffer, 2) = %s\n", itoa(-100, buffer, 2));       // Expected: "1100100" (negative not handled in other bases)
    printf("itoa(0, buffer, 10) = %s\n", itoa(0, buffer, 10));           // Expected: "0"
    printf("itoa(0, buffer, 16) = %s\n", itoa(0, buffer, 16));           // Expected: "0"
    printf("itoa(123456789, buffer, 10) = %s\n", itoa(123456789, buffer, 10)); // Expected: "123456789"
    printf("itoa(-123456789, buffer, 10) = %s\n", itoa(-123456789, buffer, 10)); // Expected: "-123456789"
    printf("itoa(31, buffer, 8) = %s\n", itoa(31, buffer, 8));           // Expected: "37"
    printf("itoa(-31, buffer, 8) = %s\n", itoa(-31, buffer, 8));         // Expected: "37" (negative not handled in other bases)
    printf("itoa(1000, buffer, 36) = %s\n", itoa(1000, buffer, 36));     // Expected: "rs"
    printf("itoa(-1000, buffer, 36) = %s\n", itoa(-1000, buffer, 36));   // Expected: "rs" (negative not handled in other bases)
    printf("itoa(2147483647, buffer, 10) = %s\n", itoa(2147483647, buffer, 10)); // Expected: "2147483647"
    printf("itoa(-2147483648, buffer, 10) = %s\n", itoa(-2147483648, buffer, 10)); // Expected: "-2147483648"
    printf("itoa(2147483647, buffer, 16) = %s\n", itoa(2147483647, buffer, 16)); // Expected: "7fffffff"
    printf("itoa(-2147483648, buffer, 16) = %s\n", itoa(-2147483648, buffer, 16)); // Expected: "7fffffff" (negative not handled in other bases)
    printf("itoa(123, buffer, 36) = %s\n", itoa(123, buffer, 36));       // Expected: "3f"
    printf("itoa(-123, buffer, 36) = %s\n", itoa(-123, buffer, 36));     // Expected: "3f" (negative not handled in other bases)


    printf("==============================================\n");
    // Test cases
    itoa(123, buffer, 10);
    printf("itoa(123, buffer, 10) = %s\n", buffer);       // Expected: "123"

    itoa(-123, buffer, 10);
    printf("itoa(-123, buffer, 10) = %s\n", buffer);     // Expected: "-123"

    itoa(255, buffer, 16);
    printf("itoa(255, buffer, 16) = %s\n", buffer);       // Expected: "ff"

    itoa(-255, buffer, 16);
    printf("itoa(-255, buffer, 16) = %s\n", buffer);     // Expected: "ff" (negative not handled in other bases)

    itoa(100, buffer, 2);
    printf("itoa(100, buffer, 2) = %s\n", buffer);         // Expected: "1100100"

    itoa(-100, buffer, 2);
    printf("itoa(-100, buffer, 2) = %s\n", buffer);       // Expected: "1100100" (negative not handled in other bases)

    itoa(0, buffer, 10);
    printf("itoa(0, buffer, 10) = %s\n", buffer);           // Expected: "0"

    itoa(0, buffer, 16);
    printf("itoa(0, buffer, 16) = %s\n", buffer);           // Expected: "0"

    itoa(123456789, buffer, 10);
    printf("itoa(123456789, buffer, 10) = %s\n", buffer); // Expected: "123456789"

    itoa(-123456789, buffer, 10);
    printf("itoa(-123456789, buffer, 10) = %s\n", buffer); // Expected: "-123456789"

    itoa(31, buffer, 8);
    printf("itoa(31, buffer, 8) = %s\n", buffer);           // Expected: "37"

    itoa(-31, buffer, 8);
    printf("itoa(-31, buffer, 8) = %s\n", buffer);         // Expected: "37" (negative not handled in other bases)

    itoa(1000, buffer, 36);
    printf("itoa(1000, buffer, 36) = %s\n", buffer);     // Expected: "rs"

    itoa(-1000, buffer, 36);
    printf("itoa(-1000, buffer, 36) = %s\n", buffer);   // Expected: "rs" (negative not handled in other bases)

    itoa(2147483647, buffer, 10);
    printf("itoa(2147483647, buffer, 10) = %s\n", buffer); // Expected: "2147483647"

    itoa(-2147483648, buffer, 10);
    printf("itoa(-2147483648, buffer, 10) = %s\n", buffer); // Expected: "-2147483648"

    itoa(2147483647, buffer, 16);
    printf("itoa(2147483647, buffer, 16) = %s\n", buffer); // Expected: "7fffffff"

    itoa(-2147483648, buffer, 16);
    printf("itoa(-2147483648, buffer, 16) = %s\n", buffer); // Expected: "7fffffff" (negative not handled in other bases)

    itoa(123, buffer, 36);
    printf("itoa(123, buffer, 36) = %s\n", buffer);       // Expected: "3f"

    itoa(-123, buffer, 36);
    printf("itoa(-123, buffer, 36) = %s\n", buffer);     // Expected: "3f" (negative not handled in other bases)

}


